import pandas as pd

from openpyxl import load_workbook

import util.lib as lib
import util.mydecorator as mydecorator

import format

@mydecorator.calTime
def job():
    # 加载 Excel 文件
    wb = load_workbook(lib.data_path + 'week_level_point.xlsx')

    for sheet_name in wb.sheetnames:
        # 获取当前 Sheet
        sheet = wb[sheet_name]

        # 冻结首行（第一行）
        sheet.freeze_panes = 'A2'  # 表示冻结 A2 单元格上方的行（即第一行）

        # 设置第一列的宽
        sheet.column_dimensions['A'].width = 30 

        sheet.conditional_formatting.add('F2:F500', format.week_inc_num_rule)

        sheet.conditional_formatting.add('G2:G2100', format.drawdown_rule)

        # lp
        sheet.conditional_formatting.add('H2:H550', format.lplt10_rule)
        sheet.conditional_formatting.add('H2:H550', format.lplt20_rule)
        sheet.conditional_formatting.add('H2:H550', format.lpgt99_rule)

        # rellp
        sheet.conditional_formatting.add('I2:I550', format.rellp_rule)

        # week_pct
        sheet.conditional_formatting.add('D2:D550', format.week_pct_rule)

        sheet['N1'].fill = format.yellow_fill
        sheet['O1'].fill = format.yellow_fill
        sheet['P1'].fill = format.yellow_fill
        sheet['Q1'].fill = format.yellow_fill
        sheet.conditional_formatting.add('N2:N550', format.week_pct_rule)
        sheet.conditional_formatting.add('O2:O550', format.week_pct_rule)
        sheet.conditional_formatting.add('P2:P550', format.week_pct_rule)
        sheet.conditional_formatting.add('Q2:Q550', format.week_pct_rule)

    wb.save(lib.data_path + 'week_level_point_v.xlsx')



if __name__ == '__main__':
    job()